package main

import (
	_ "encoding/hex"
	_ "github.com/tarm/serial"
	_ "log"
	_ "net/http/pprof"
	"sync"
)

func init() {
}

var applicationWaitGroup sync.WaitGroup

func main() {
	applicationWaitGroup.Add(1)
	applicationWaitGroup.Wait()
}

//handleBarrierMessage(85)

//// 根据道闸显示器配置建立led485连接,开启led485ConnTask
//var waitingLed485MapSet sync.WaitGroup
//waitingLed485MapSet.Add(len(led485Config.GetLed485Info()))
//for _, led485configArray := range led485Config.GetLed485Info() {
//	key := led485configArray.GetName()
//	serialConf := &serial.Config{
//		Name:        "/dev/ttyUSB" + key,         // 根据实际情况修改串口名称
//		Baud:        led485configArray.GetBaud(), // 波特率
//		ReadTimeout: led485configArray.GetReadTimeout(),
//	}
//	go func(key string) {
//		defer waitingLed485MapSet.Done()
//		port := led485ConnTask(serialConf)
//		led485ConnMap[key] = port
//	}(key)
//}
//waitingLed485MapSet.Wait()
//logger.Infof("led485ConnMap: %v", led485ConnMap)

//pinNumber := 85 // 使用 GPIO 85
//gpioPath := fmt.Sprintf("/sys/class/gpio/gpio%d", pinNumber)
//exportFile := "/sys/class/gpio/export"
//directionFile := gpioPath + "/direction"
//valueFile := gpioPath + "/value"
////unexportFile := gpioPath + "/unexport"
//
//// 检查 GPIO 引脚是否已经导出
//if _, err := os.Stat(gpioPath); os.IsNotExist(err) {
//	// GPIO 引脚未导出，导出它
//	if err := os.WriteFile(exportFile, []byte(fmt.Sprintf("%d", pinNumber)), 0644); err != nil {
//		log.Fatalf("failed to export GPIO %d: %v", pinNumber, err)
//	}
//	fmt.Printf("GPIO %d has been exported\n", pinNumber)
//	// 设置引脚方向为输出
//	if err := os.WriteFile(directionFile, []byte("out"), 0644); err != nil {
//		log.Fatalf("failed to set GPIO %d direction to out: %v", pinNumber, err)
//	}
//} else {
//	// GPIO 引脚已导出，无需重复导出
//	fmt.Printf("GPIO %d is already exported\n", pinNumber)
//}
//
//// 等待内核创建引脚目录
//time.Sleep(100 * time.Millisecond)
//
//// 控制引脚值
//if err := os.WriteFile(valueFile, []byte("1"), 0644); err != nil {
//	log.Fatalf("failed to set GPIO %d value to high: %v", pinNumber, err)
//}
//fmt.Printf("GPIO %d is now high\n", pinNumber)
//
//time.Sleep(2 * time.Second)
//
//if err := os.WriteFile(valueFile, []byte("1"), 0644); err != nil {
//	log.Fatalf("failed to set GPIO %d value to high: %v", pinNumber, err)
//}
//
//time.Sleep(1000 * time.Second)

//------------------------------------------------------------
//config := &serial.Config{
//	Name:        "/dev/ttyUSB0", // 根据实际情况修改串口名称
//	Baud:        19200,         // 波特率
//	ReadTimeout: time.Second * 100,
//}
//// 打开串口
//port, err := serial.OpenPort(config)
//if err != nil {
//	log.Fatalf("Failed to open port: %v", err)
//}
//
//// 准备要发送的数据
//hexString :="0064FFFF6F9800000400150105000300FF00000008BEA94138383838380D01150105000300FF00000006C4DAB2BFB3B50D02150105000300FF00000008CDA3B3B530B7D6200D03150105000300FF00000017202020CEDEC8EBB3A1BCC7C2BC20D6D8B8B4CAB6B1F020000A31BEA941383838383820C4DAB2BFB3B520CDA3B3B530B7D6202020202020CEDEC8EBB3A1BCC7C2BC20D6D8B8B4CAB6B1F02000FF34"
//data, err := hex.DecodeString(hexString)
//logger.Infof("写入数据: %x",data)
//// 发送数据
//n, err := port.Write(data)
//if err != nil {
//	log.Fatalf("Failed to write to port: %v", err)
//}
//fmt.Printf("Wrote %d bytes to port\n", n)
//
//buffer := make([]byte, 1024)
//l, err := port.Read(buffer)
//if err != nil {
//	log.Fatalf("s.Read: %v", err)
//}
//// 打印读取到的数据
//fmt.Printf("Read %d bytes: %q\n", l, buffer[:l])
//time.Sleep(10000 * time.Second)
